﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

namespace Enterprise.Management.Gridview
{
    public class Gridview
    {
        public GridviewHeader Header { get; set; }
        public List<GridviewRow> Rows { get; set; }
        public GridviewPage Page { get; set; }
        public string ID { get; set; }

        public Gridview()
            : this(new GridviewPage())
        {
            
        }

        public Gridview(GridviewPage page)
        {
            ID = Guid.NewGuid().ToString();
            Header = new GridviewHeader();
            Rows = new List<GridviewRow>();
            Page = page;
        }

        public void Fill<T>(List<T> data)
        {
            for (int i = 0; i < data.Count; i++)
            {
                GridviewRow row = new GridviewRow();
                row.RowId = i;
                row.Data = data[i];
                foreach (var column in Header.Cells)
                {
                    GridviewCell cell = new GridviewCell();
                    cell.Value = column.RowValue;
                    cell.DataTemplate = column.RowDataTemplate;
                    cell.Formatter = column.RowFormatter;
                    row.Cells.Add(cell);
                }
                Rows.Add(row);
            }
        }

        
    }
}